Includes an aggregation subquery into the incremental maintenance mechanism of a view.

Namespace:  C1.LiveLinq.LiveViews
Assembly:  C1.Silverlight.LiveLinq (in C1.Silverlight.LiveLinq.dll)

Syntax

C#
public AggregationView<T, TResult> AttachAggregationView<TResult>(
	Func<View<T>, AggregationView<T, TResult>> selector
)
Visual Basic
Public Function AttachAggregationView(Of TResult) ( _
	selector As Func(Of View(Of T), AggregationView(Of T, TResult)) _
) As AggregationView(Of T, TResult)

Parameters

selector
Type: System..::..Func<(Of <(<'View<(Of <(<'T>)>)>, AggregationView<(Of <(<'T, TResult>)>)>>)>)>
A function to obtain the attached aggregation subview from the view to which it is attached.

Type Parameters

TResult
The type of the elements in the aggregation subview.

Return Value

The attached aggregation subview.

Remarks

Subquery is a query inside a function that is a part of an outer query. If the outer query is a live view, and its base data changes so it needs to recompute the function, by default it just evaluates the function, which means creating a new view object for the subquery on every such recomputation. To improve performance by avoiding repeated creation of subviews, use the AttachAggregationView method to make the outer view aware of its subview. Then the outer view will cache and reuse subview objects it creates.

If there are more than one subviews attached to a single view, every subview must be supplied with a unique subview id by using the AttachAggregationView overload with subviewId parameter.

Examples

Copy CodeC#
var productView =
    from p in products
    join s in sales on p.ProductID equals s.ProductID into productSales
    select new
    {
        p.Name,
        ProductTotal = productSales.AttachAggregationView(v => v.LiveSum(s => s.Quantity))
    };

See Also